	<style>
dt{
    color: #333333;
    float: left;
    margin: 0;
    padding: 4px 0 0;
    text-align: right;
	width:80px;
	font-weight:600;
	font-size:14px;
}

dd{
	 margin-left: 10px;
      padding: 4px 0 4px 5px;
	line-height:25px;
	overflow:hidden;
	width:880px;
}	
dl{clear:both;line-height:25px;}
a{color:blue;font-size:12px;}
#cate_more,#company_more{float:right;cursor:pointer;}
.select-bar{padding:15px;border:1px solid gray;margin-top:15px;}
#center-column .selected{width:97%;height:auto;background:none repeat scroll 0 0 #BBD9EE;padding:15px;border:1px solid gray;}
#center-column .selected ul{float:left;width:800px;padding:0px;}
#center-column .selected li{list-style-type:none; width:500px;font-size:18px;float:left;height:20px;line-height:20px;padding:5px;margin-left:10px;margin-top:10px;}
#center-column .selected li span{color:green;}
.search_mod{width:auto;}
.color{border:1px solid blue;}
.or{overflow:hidden;height:30px;}
.trs,.selected img,#clear_all,.update_version,.second_send{cursor:pointer;}
.version{display:none;}
.simplemodal-data{ width:1100px;  height:auto; overflow-y:auto; overflow-x:hidden; background:#fff; border:6px #2b2b2b solid; padding:16px;}
.bs{ background-color:#BBD9EE;}
.order_tag{color:blue;cursor:pointer;}
</style>


    <input type="hidden" value="0" id="cate" />
    <input type="hidden" value="<?php echo $user[0]->role;?>" id="role" />
		<div id="center-column">
	    <div class="select-bar">
		     <dl><dt>资料合计：</dt>
		         <dd><span style="float:left;"><?php echo $modcount;?>个型号&nbsp;&nbsp;<?php echo $categorycount;?>种用户技术资料&nbsp;&nbsp;<?php echo $totalcount;?>份技术资料</span>
		             <span style="float:right;color:#FF0000;font-size:12px;">：&nbsp;<?php echo $invalid_category;?>种用户技术资料&nbsp;&nbsp;<?php echo $invalid_files;?>份技术资料 </span>
		             <span style="float:right;color:#FF0000;font-weight:600;font-size:14px;">未更新至最新版本 </span> 
		         </dd>
		     </dl>
		     <?php if($modcount==1){?>
		     <dl><dt>成套资料</dt>
		         <dd><?php echo $total_complete;?>个全套资料&nbsp;&nbsp;<?php   if($temp_com!=""){echo $temp_com;}?></dd>
		     </dl>
		     <?php }?>
		  </div>
          

			<div class="table">
<script>
function fnSetDateFormat(oDateFormat)
{
	oDateFormat['FullYear'];		//Example = 2007
	oDateFormat['Year'];			//Example = 07
	oDateFormat['FullMonthName'];	//Example = January
	oDateFormat['MonthName'];		//Example = Jan
	oDateFormat['Month'];			//Example = 01
	oDateFormat['Date'];			//Example = 01
	oDateFormat['FullDay'];			//Example = Sunday
	oDateFormat['Day'];				//Example = Sun
	oDateFormat['Hours'];			//Example = 01
	oDateFormat['Minutes'];			//Example = 01
	oDateFormat['Seconds'];			//Example = 01

	var sDateString;
	
	return sDateString;
}

  $(document).ready(function(){
	  $("#order_by").children("span").each(function(){
         $(this).click(function(){
            var order = $(this).attr("title");
            $("#orderby").val(order);
            $("#index_form").submit();
         })
	  })
  })
</script>			    
				<div id="order_by" style="display:none;"><span title="0">排序方式：</span>&nbsp;&nbsp;&nbsp;<span title="0" class="order_tag">默认排序</span>&nbsp;&nbsp;&nbsp;<span title="1" class="order_tag">更新时间</span>&nbsp;&nbsp;&nbsp;<span title="2" class="order_tag">发放时间</span></div>	
				<br/><table class="listing" cellpadding="0" cellspacing="0">
					<tr>
						<th class="first" width="100">型号</th>
						<th>资料编码</th>
						<th>资料名称</th>
						<th>密级</th>
						<th>有效版次</th>
						<th>总份数</th>
						<th>已更新</th>
						<th>未更新</th>
						<th>库存量</th>
						<th>发放单位</th>
						<th></th>						
					</tr>
					
					<?php foreach($category as $k=>$val):?>
					<tr <?php if($val->need_update==1){?>class="bs"<?php }?>>
						<td class="first style1"><?php foreach($mod as $i=>$j){ if($j->mod_id==$val->mod_id){echo $j->name;}}?></td>
						<td><?php echo $val->codes;?></td>
						<td style="text-align:left;padding-left:5px;"><?php echo $val->name;?></td>
						<td><?php echo $level_data[$val->level];?></td>						
						<td><?php echo $val->valid_version;?></td>
						<td><?php echo $val->total_count;?></td>
						<td><?php echo $val->valid_count;?></td>
						<td><?php echo $val->invalid_count;?></td>
						<td><?php echo $val->left_count;?></td>						
						<td class="last"><?php if($val->company==""){echo "此资料没有发放记录！";}else{echo $val->company;}?></td>
						<td class="trs" id="<?php echo $val->category_id;?>" style="color: blue;text-decoration:underline">查看明细</td>
					</tr>
				<?php endforeach;?>	
					
				</table>
				<div><?php echo $page;?>
			  </div>
			</div>
			<div class="selected">
             <div style="float:left;font-size:18px;width:90px;">筛选条件：</div><ul><li class="search_mod color" id="search_mod">型号：<span id="mod_span"><?php if($select_mod_id!=""){ foreach($mod as $k=>$val){ if($val->mod_id==$select_mod_id){ echo $val->name;}} }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='mod'/></li>
                 <li class="color" id="search_name">资料名称：<span id="category_span"><?php if($select_category_id!=""){ foreach($cate as $k=>$val){ if($select_category_id==$val->category_id){ echo $val->name; } } }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='category'/></li>
                 <li class="color" id="search_company">发放单位：<span id="company_span"><?php if($select_company_id!=""){ foreach($company as $k=>$val){ if($select_company_id==$val->company_id){echo $val->name;}} }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='company'/></li>
                 <li class="color" id="search_version">当前版次：<span id="version_span"><?php if($select_version_id!=""){ foreach($version as $k=>$val){ if($select_version_id==$val->version_id){ echo $val->name;}} }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='version2'/></li>
                 <li class="color" id="search_level">密级：<span id="level_span"><?php if($select_level!=""){ echo $level_data[$select_level]; }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='level'/></li>
                 <li class="color" id="search_update">更新情况：<span id="update_span"><?php if($select_update!=""){ echo $update_data[$select_update]; }else{?>全部<?php }?></span><img src='<?php echo base_url();?>img/hr.gif' class='update'/></li>
                 <li ><span id="clear_all">全部清空</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" value="检索" id="sdub" style="float:right;" /></li>
             </ul>

		   <?php echo form_open('main/index',array('id'=>'index_form'));?> 
		     <input type="hidden"  id="mod" name="mod" value="<?php echo $select_mod_id;?>" />
		     <input type="hidden"  id="category" name="category" value="<?php echo $select_category_id;?>" />
		     <input type="hidden"  id="version" name="version" value="<?php echo $select_version_id;?>" />
		     <input type="hidden"  id="company" name="company" value="<?php echo $select_company_id;?>" />
		     <input type="hidden"  id="level" name="level" value="<?php echo $select_level;?>" />
		     <input type="hidden"  id="update" name="update" value="<?php echo $select_update;?>" />
		     
 		    <dl class="mod">
		        <dt>型代号：</dt>
		        <dd><a href="javascript:void(0)" alt="">全部</a>&nbsp;&nbsp;<?php foreach($mod as $k=>$val):?><a href="javascript:void(0)" alt="<?php echo $val->mod_id?>"><?php echo $val->name;?></a>&nbsp;&nbsp;<?php endforeach;?></dd>
		    </dl>
		    <dl class="or category" style="display:none;">
		        <dt>资料名称：</dt>
		        <dd><div id="cate_more" width="30px;">&nbsp;&nbsp;更多&nbsp;&nbsp;</div><div id="category_detail"><a href="javascript:void(0)" alt="">全部</a>&nbsp;&nbsp;&nbsp;&nbsp;</div></dd>
		    </dl>
		    <dl class="company">
		        <dt>发放单位：</dt>
		        <dd><div id="company_more" width="30px;">&nbsp;&nbsp;更多&nbsp;&nbsp;</div><div id="company_detail"><a href="javascript:void(0)" alt="">全部</a>&nbsp;&nbsp;<?php foreach($company as $k=>$val):?><a href="javascript:void(0)" alt="<?php echo $val->company_id;?>"><?php echo $val->name;?></a>&nbsp;&nbsp;<?php endforeach;?></div></dd>
		    </dl>
		    <dl class="update">
		        <dt>更新情况：</dt>
		        <dd><a href="javascript:void(0)" alt="">全部</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="0">库存已更新</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="1">库存未更新</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="2">发放已更新</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="3">发放未更新</a></dd>
		    </dl>
		    <dl class="version">
		        <dt>当前版次：</dt>
		        <dd></dd>
		    </dl>
		    <dl class="level">
		        <dt>资料密级：</dt>
		        <dd><a href="javascript:void(0)" alt="">全部</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="0">机密</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="1">秘密</a>&nbsp;&nbsp;<a href="javascript:void(0)" alt="2">内部</a>&nbsp;&nbsp;</dd>
		    </dl>
<!-- 		    <dl> -->
<!-- 		        <dt>接收日期：</dt>
		        <dd><input name='first_time' id='first_time' class='date-pick' value="<?php echo $first_time;?>" ><span style="float:left;">
		            &nbsp;&nbsp;发出日期：</span><input name='second_time' id='second_time' class='date-pick' value="<?php echo $second_time;?>"  >
		            <span style="float:left;">&nbsp;&nbsp;更改日期：</span><input name='third_time' id='third_time' class='date-pick' value="<?php echo $third_time;?>"  >
<!-- 		            &nbsp;&nbsp;</dd> -->
<!-- 		    </dl> -->
		    <input type="hidden" value="" name="orderby" id="orderby">
           </form>   
		  </div>
		</div>
	</div>
	
<!-- 接收更新弹层 -->	
 <div id="receive_detail">

 </div>
	<div id="footer"></div>
</div>
<div id="version_detail" style="height-max:700px;scroll:auto;">
   
</div>

</body>
</html>

<script language="javascript">

  $(document).ready(function(){
	  $("#sdub").click(function(){
        $("#index_form").submit();
      })
	  $('.date-pick').datePicker({startDate:'1996.01.01'});
      $("#cate_more,#company_more").click(function(){
          var cate = $("#cate").val();
          if(cate==0){
             $(this).parents("dl").removeClass("or");
             $("#cate").val("1");
          }else{
        	 $(this).parents("dl").addClass("or");
        	 $("#cate").val("0");
          }
      })
      $(".category a").each(function(){
             $(this).click(function(){
            	 var category_id = $(this).attr("alt");
                 var category = $(this).html();
                 $("#category_span").html();
                 $("#category_span").html(category);
                 $("#category").val(category_id);
                 $.ajax({
    		    	   type: "POST",
    		    	   url: "<?php echo base_url();?>main/getversion",
    		    	   data: "category_id="+category_id,
    		    	   success: function(msg){
                            $(".version dd").html(msg);  
                            $(".version").show(); 
    		    	   } 
    		    	});
             })        
      })
      
     $(".mod a").each(function(){
             $(this).click(function(){
                 var mod_id = $(this).attr("alt");
                 var mod = $(this).html();
                 $("#mod_span").html();
                 $("#mod_span").html(mod);
                 $("#mod").val(mod_id);
                 $.ajax({
    		    	   type: "POST",
    		    	   url: "<?php echo base_url();?>main/getcategory",
    		    	   data: "mod_id="+mod_id,
    		    	   success: function(msg){
                            $("#category_detail").html(msg);  
                            $("#category_detail").parents(".category").show();
    		    	   } 
    		    	});
             })        
      })
      $(".company a").each(function(){
             $(this).click(function(){
                 var company_id = $(this).attr("alt");
                 var company = $(this).html();
                 $("#company_span").html();
                 $("#company_span").html(company);
                 $("#company").val(company_id);
             })        
      })
      $(".level a").each(function(){
             $(this).click(function(){
                 var level_id = $(this).attr("alt");
                 var level = $(this).html();
                 $("#level_span").html();
                 $("#level_span").html(level);
                 $("#level").val(level_id);
             })        
      })
      $(".update a").each(function(){
             $(this).click(function(){
                 var update_id = $(this).attr("alt");
                 var update = $(this).html();
                 $("#update_span").html();
                 $("#update_span").html(update);
                 $("#update").val(update_id);
             })        
      })
   
      $(".selected img").each(function(){
             $(this).click(function(){
                 var at=$(this).attr("class");
                
                 var sp="#"+at+"_span";
                 var ids = "#"+at;
                 if(at=="version2"){
                     var  sp="#version_span";
                     var  ids = "#version";
                 }
                 $(sp).html("全部");
                 $(ids).val('');
             })
      })      
      $("#clear_all").click(function(){
          $("#mod_span").html("全部");
          $("#category_span").html("全部");
          $("#level_span").html("全部");
          $("#update_span").html("全部");
          $("#company_span").html("全部");
          $("#version_span").html("全部");
          $("#mod").val("");
          $("#version").val("");
          $("#category").val("");
          $("#update").val("");
          $("#level").val("");
          $("#company").val("");
          $("#orderby").val("");
          $("#index_form").submit();
      })
      $(".trs").click(function(){
          var category_id = $(this).attr("id");
          var role = $("#role").val();
          $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>main/get_category_detail",
        	   data: "category_id="+category_id,
               dataType:"json", 
        	   success: function(msg){   
            	  var str = "<table class='listing form' cellpadding='0' cellspacing='0' style='width:1070px;'>";
            	  str+="<tr><th class='first' width='90'>型号</th><th width='90'>资料名称</th><th width='40'>密级</th><th width='40'>当前版次</th><th width='40'>有效版次</th><th width='40'>总份数</th><th width='60'>发往单位</th><th width='40'>发放时间</th>";
            	  if(role==0){
                      str+="<th class='last' width='70'>二次分发</th>";
			       	}
		       	str+="<th width='70'>更新提示</th><th width='70'>备注</th></tr>";
        	      for(var i=0;i<msg.length;i++){
                       str+="<tr><td><input type='hidden' value='"+msg[i].id+"' /><input type='hidden' value='"+msg[i].company+"' />"+msg[i].mod+"</td><td title="+msg[i].category+">"+msg[i].category.substr(0,8)+"</td><td>"+msg[i].level+"</td><td>"+msg[i].current_version+"</td><td>"+msg[i].valid_version+"</td><td>"+msg[i].total_count+"</td><td>"+msg[i].company+"</td><td>"+msg[i].sendtime+"</td>";
                       if(role==0){
                           str+="<td><span class='second_send' onclick='second_send(this)'>"+msg[i].updatedes+"</span></td><td>";
			   	    	}else{
                            str+="<td>";
				   	    	}
                        if(msg[i].current_version==msg[i].valid_version){
                    	      str+="</td><td>"+msg[i].des+"</td></tr>";
                          }else{
                              if(role==0){
                        	    str+="<span class='update_version' onclick='update_version(this)'><font color='red'>更新版次</font></span></td>";
                              }else{
                            	  str+="<span><font color='red'>更新版次</font></span></td>";
                              }
                              str+="<td>"+msg[i].des+"</td></tr>";          
                          }
                                   
                	  }
          	          str+="</table>"; 
            	 $("#version_detail").html("");
          	     $("#version_detail").append(str);      	  
    	         $("#version_detail").modal();
        	   }
        	});
      })

    })
  
  function version_click(v){
	  var version_id = $(v).attr("alt");
      var version = $(v).html();
      $("#version_span").html();
      $("#version_span").html(version);
      $("#version").val(version_id);
  }    


  function category_click(v){
	  var category_id = $(v).attr("alt");
      var category = $(v).html();
      $("#category_span").html();
      $("#category_span").html(category);
      $("#category").val(category_id);

      $.ajax({
	    	   type: "POST",
	    	   url: "<?php echo base_url();?>main/getversion",
	    	   data: "category_id="+category_id,
	    	   success: function(msg){
                 $(".version dd").html(msg);  
                 $(".version").show(); 
	    	   } 
	    	});
   }

  
  function update_receive_data(){
	  	var receive_id = $("#receive_id").val();
	    var mod_id = $("#mod_id").val();
	    var category_id = $("#category_id").val();
	    var count = $("#count").val();
	    var codes = $("#codes").val();
	    var version_id = $("#version_id").val();
	    var pre_version = $("#pre_version").val();
	    var pre_count = $("#pre_count").val();
	    var pre_count_record = $("#pre_count_record").val();
	    var pre_codes = $("#pre_codes").val();
        var contacter = $("#contacter").val();
        var updatetime = $("#updatetime").val();
	    var v = $("#version_id").find("option:selected").text();
	      var preversion = $("#current_id_notice").html();
	      var v=v.replace(".","");
	      var v=v.replace(".","");
	      var preversion=preversion.replace(".","");            
	      var preversion=preversion.replace(".","");
	      if(parseInt(v)<=parseInt(preversion)){
	    	  alert('更新至版次必须高于当前版次');
	    	  return false;
	      }  
	    if(version_id==""){
           alert("接收版次不能空!");
           return false;
		}
	    if(codes==""){
           alert('接收单号不能空!');
           return false;
	    }
	    if(count==""){
           alert("接收份数不能空!");
           return false;
		}
	    if(updatetime==""){
	           alert("更新时间不能空!");
	           return false;
	    }
	    
	    var str = "updatetime="+updatetime+"&contacter="+contacter+"&pre_count_record="+pre_count_record+"&pre_codes="+pre_codes+"&codes="+codes+"&mod_id="+mod_id+"&category_id="+category_id+"&version_id="+version_id+"&pre_version="+pre_version+"&pre_count="+pre_count+"&count="+count+"&receive_id="+receive_id;
	    $.ajax({
	    	   type: "POST",
	    	   url:"<?php echo  base_url();?>administrator/update_receive",
	    	   data: str, 
	    	   success: function(msg){          	  
	                
	                if(msg=='1'){
	                  alert("操作成功!");
	                  $(".simplemodal-close").click();
	                  window.location.reload();
	                }else{
                      alert(msg);
		            }
	                
	    	   }
	    	});

  }


  function update_send_data(){
	  
	  var send_id = $("#send_id").val();
      var mod_id = $("#mod_id").val();
      var category_id = $("#category_id").val();
      var des = $("#des").val();
      var codes = $("#codes").val();
      var count = $("#count").val();
      var sendtime = $("#sendtime").val();
      var version_id = $("#version_id").val();
      var pre_version = $("#pre_version").val();
      var pre_count = $("#pre_count").val();
      var pre_codes = $("#pre_codes").val();
      var company_id = $("#company_id").val();
      var user_id = $("#user_id").val();
      var updatetime = $("#updatetime").val();
      var v = $("#version_id").find("option:selected").text();
      var preversion = $("#current_id_notice").html();
      var v=v.replace(".","");
      var v=v.replace(".","");
      var preversion=preversion.replace(".","");            
      var preversion=preversion.replace(".","");
      
      if(parseInt(v)<=parseInt(preversion)){
    	  alert('更新至版次必须高于当前版次');
    	  return false;
      }
      if(codes==""){
          alert("发放单据号不能空!");
          return false;
      }
      if(count==""){
          alert("资料份数不能空!");
          return false;
      }
      if(updatetime==""){
          alert("更新时间不能空!");
          return false;
      }
      var str = "sendtime="+sendtime+"&updatetime="+updatetime+"&user_id="+user_id+"&pre_codes="+pre_codes+"&codes="+codes+"&company_id="+company_id+"&mod_id="+mod_id+"&category_id="+category_id+"&des="+des+"&version_id="+version_id+"&pre_version="+pre_version+"&pre_count="+pre_count+"&count="+count+"&send_id="+send_id;
      $.ajax({
      	   type: "POST",
      	   url:"<?php echo  base_url();?>administrator/update_send",
      	   data: str, 
      	   success: function(msg){    
        		 $("#submit").attr("disabled",true);                   
                  if(msg=='1'){
                    alert("操作成功!");
                    $(".simplemodal-close").click();
                    $("#submit").attr("disabled",false);
                    window.location.reload();
                  }else{
                     alert(msg);
                     $("#submit").attr("disabled",false);
                    }
      	   }
      	});
  }
    function check_version(v){
        var v = $(v).find("option:selected").text();
        var pre_version = $("#current_id_notice").html();
        var v=v.replace(".","");
        var v=v.replace(".","");
        var pre_version=pre_version.replace(".","");            
        var pre_version=pre_version.replace(".","");

        if(parseInt(v)<=parseInt(pre_version)){
            alert('更新至版次必须高于当前版次');
        }
    }

  
	function send_update(send_id){
        $.ajax({
        	   type: "POST",
        	   url:"<?php echo  base_url();?>administrator/get_send_for_layout",
        	   data: "send_id="+send_id,
               dataType:'json', 
        	   success: function(msg){   
      var st = '<table class="listing form" cellpadding="0" cellspacing="0" style="width:550px;margin-left:185px;"><input type="hidden" id="pre_count" /><input type="hidden" id="pre_version" /><input type="hidden" id="mod_id" /><input type="hidden" id="send_id" /><input type="hidden" id="sendtime" /><input type="hidden" id="category_id" /><input type="hidden" id="company_id" /><input type="hidden" id="pre_codes" />';
		  st+='<tr><th  colspan="2"  align="center">更新发放版次</th></tr>';
		  st+='<tr><td style="width:100px;text-align:right;"><strong>型号：</strong></td><td style="text-align:left;"><span id="mod_id_notice"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000">版次更新状态下、型号、资料种类、资料当前版本不可以更改</font></td></tr>';
		  st+='<tr><td style="width:100px;text-align:right;"><strong>资料种类：</strong></td><td style="text-align:left;"><span id="category_id_notice"></span></td></tr>';
		  st+='<tr><td style="width:100px;text-align:right;"><strong>资料当前版本：</strong></td><td style="text-align:left;"><span id="current_id_notice">'+msg.current_version+'</span></td></tr>';
		  st+='<tr><td style="width:100px;text-align:right;"><strong>发放单位：</strong></td><td style="text-align:left;">'+msg.company+'</td></tr>';
		  st+='<tr><td style="width:100px;text-align:right;"><strong>更新至版本：</strong></td><td style="text-align:left;"><select name="version_id" id="version_id" onchange="check_version(this)"></select><span id="version_id_notice">&nbsp;&nbsp;<font color="#FF0000">更新至版次必须高于当前版次</font></span></td></tr>';
		  st+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新单据号：</strong></td><td style="text-align:left;"><input type="text" class="text" name="codes" id="codes" value="" /></td></tr>';
		  st+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新人员：</strong></td><td style="text-align:left;"><input type="text" class="text" name="user_id" id="user_id" value="张永军" /></td></tr>';
		  st+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新时间：</strong></td><td style="text-align:left;"><input type="text" name="updatetime" id="updatetime" value="" onmouseover=InitCalendar(this,"style=calendar.css,close=true") readonly/><img src="<?php echo site_url();?>img/cal.gif" align="absmiddle" onmouseover=InitCalendar(this,"style=calendar.css,close=true")><span>1970.01.01</span></td></tr>';
		  st+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新份数：</strong></td><td style="text-align:left;"><input type="text" class="text" name="count" onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) id="count" value="" /><span id="count_notice"></span></td></tr>';
		  st+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>备注：</strong></td><td style="text-align:left;"><textarea name="des" cols="50" rows="5" id="des"></textarea></td></tr>';
		  st+='<tr><td colspan="2"><input type="button" value="提交" class="button" onclick="update_send_data()" id="submit"/><input type="button" value="返回" class="button" onclick="return_receive('+msg.category_id+')"/></td></tr></table>';   
		  $("#version_detail").html('');	   
		  $("#version_detail").html(st);   	          	  
          	   $("#mod_id_notice").html(msg.mod);
          	   $("#category_id_notice").html(msg.category);
          	   $("#version_id").html(msg.version);
          	   $("#count").val(msg.count);
          	   $("#mod_id").val(msg.mod_id);
          	   $("#send_id").val(msg.send_id);
          	   $("#category_id").val(msg.category_id);
          	   $("#company_id").val(msg.company_id);
          	   $("#pre_count").val(msg.count);
          	   $("#pre_version").val(msg.pre_verison);
          	   $("#des").val(msg.des);
          	   $("#pre_codes").val(msg.codes);  	
               $("#sendtime").val(msg.sendtime);        
        	   }
        	});
		
	}

function receive_update(receive_id){
      $.ajax({
    	   type: "POST",
    	   url:"<?php echo  base_url();?>administrator/get_receive_for_layout",
    	   data: "inventory_id="+receive_id,
           dataType:'json', 
    	   success: function(msg){          	  

  var sss = '<table class="listing form" cellpadding="0" cellspacing="0" style="width:600px;margin-left:170px;">';
      sss+='<input type="hidden" id="pre_count" />';
      sss+='<input type="hidden" id="pre_version" />';
      sss+='<input type="hidden" id="mod_id" />';
      sss+='<input type="hidden" id="receive_id" />';
      sss+='<input type="hidden" id="category_id" />';
      sss+='<input type="hidden" id="pre_codes" />';
      sss+='<input type="hidden" id="pre_count_record" />';
      sss+='<tr><th  colspan="2"  align="center">更新库存版次</th></tr>';
      sss+='<tr><td style="width:100px;text-align:right;"><strong>型号：</strong></td><td style="text-align:left;">';
      sss+='<span id="mod_id_notice">'+msg.mod+'</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#FF0000">版次更新状态下、型号、资料种类、资料当前版本不可以更改</font></td></tr>';
      sss+='<tr><td style="width:100px;text-align:right;"><strong>资料种类：</strong></td><td style="text-align:left;"><span id="category_id_notice">'+msg.category+'</span></td></tr>';
      sss+='<tr><td style="width:100px;text-align:right;"><strong>资料当前版本：</strong></td><td style="text-align:left;"><span id="current_id_notice">'+msg.current_version+'</span></td></tr>';
      sss+='<tr><td style="width:100px;text-align:right;"><strong>更新至版本：</strong></td><td style="text-align:left;"><select name="version_id" id="version_id" onchange="check_version(this)">'+msg.version+'</select><span id="version_id_notice">&nbsp;&nbsp;<font color="#FF0000">更新至版次必须高于当前版次</font></span></td></tr>';
	  sss+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新单据号：</strong></td><td style="text-align:left;"><input type="text" class="text" name="codes" id="codes" value="" /></td></tr>';
	  sss+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新人员：</strong></td><td style="text-align:left;"><input type="text" class="text" name="contacter" id="contacter" value="张永军" /></td></tr>';
	  sss+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新时间：</strong></td><td style="text-align:left;"><input type="text" class="text" name="updatetime" id="updatetime" value="" /><span>1970.01.01</span></td></tr>';
	  sss+='<tr class="bg"><td style="width:100px;text-align:right;"><strong>更新份数：</strong></td><td style="text-align:left;"><input type="text" class="text" name="count" onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) id="count" value="'+msg.count+'" /><span id="count_notice"></span></td></tr>';
	  sss+='<tr><td colspan="2"><input type="button" value="提交" class="button" id="submits" onclick="update_receive_data()"/><input type="button" value="返回" class="button" onclick="return_receive('+msg.category_id+')"/></td></tr></table>';    
	  $("#version_detail").html('');	   
	  $("#version_detail").html(sss);
	  
	   $("#mod_id_notice").html(msg.mod);
  	   $("#category_id_notice").html(msg.category);
  	   $("#version_id").html(msg.version);
  	   $("#count").val(msg.count);
  	   $("#pre_codes").val(msg.codes);
  	   $("#mod_id").val(msg.mod_id);
  	   $("#receive_id").val(msg.inventory_id);
  	   $("#category_id").val(msg.category_id);
  	   $("#pre_count").val(msg.count);
       $("#pre_count_record").val(msg.count);
  	   $("#pre_version").val(msg.pre_verison);
    	   }
    	});
}  



function get_vesion_count(version){
	var mod_id = $("#mod_id").val();
	var category_id = $("#category_id").val();
	var version_id = $(version).val();
    $.ajax({
  	   type: "POST",
  	   url:"<?php echo  base_url();?>administrator/get_version_detail",
  	   data: "version_id="+version_id+"&mod_id="+mod_id+"&category_id="+category_id,
  	   success: function(msg){
      	 //库存量  
 	    	   $("#pre_count").val(msg);
 	    	   $("#count_notice").html("<font color='red'>此版本库存量仅剩"+msg+"本</font>");
  	   }
  	});
	
}




  function return_receive(category_id){
	  var role = $("#role").val();
	  $.ajax({
	   	   type: "POST",
	   	   url:"<?php echo  base_url();?>main/get_category_detail",
	   	   data: "category_id="+category_id,
	          dataType:'json', 
	   	   success: function(msg){       
	       	  var str = '<table class="listing form" cellpadding="0" cellspacing="0" style="width:1070px;">';
		       	str+="<tr><th class='first' width='90'>型号</th><th width='90'>资料名称</th><th width='40'>密级</th><th width='40'>当前版次</th><th width='40'>有效版次</th><th width='40'>总份数</th><th width='60'>发往单位</th><th width='40'>发放时间</th>";
		       	if(role==0){
                       str+="<th class='last' width='70'>二次分发</th>";
			       	}
		       	str+="<th width='70'>更新提示</th><th width='70'>备注</th></tr>";
	   	      for(var i=0;i<msg.length;i++){
		   	    	str+="<tr><td><input type='hidden' value='"+msg[i].id+"' /><input type='hidden' value='"+msg[i].company+"' />"+msg[i].mod+"</td><td title="+msg[i].category+">"+msg[i].category.substr(0,8)+"</td><td>"+msg[i].level+"</td><td>"+msg[i].current_version+"</td><td>"+msg[i].valid_version+"</td><td>"+msg[i].total_count+"</td><td>"+msg[i].company+"</td><td>"+msg[i].sendtime+"</td>";
		   	    	if(role==0){
                           str+="<td><span class='second_send' onclick='second_send(this)'>"+msg[i].updatedes+"</span></td><td>";
			   	    	}else{
                            str+="<td>";
			   	    	}
	                if(msg[i].current_version==msg[i].valid_version){
	              	      str+='</td><td>'+msg[i].des+'</td></tr>';
	                    }else{
	                    	if(role==0){
                        	    str+='<span class="update_version" onclick="update_version(this)"><font color="red">更新版次</font></span></td>';
                              }else{
                            	  str+='<span><font color="red">更新版次</font></span></td>';
                              }
	                    	str+='<td>'+msg[i].des+'</td></tr>';
	                    }
                    
	           	  }
	     	          str+='</table>'; 
	       	 $("#version_detail").html('');
	     	 $("#version_detail").append(str);   
		     $(".simplemodal-close").css({"display":"block"});   	  
	   	   }
	   	});
   }


  function update_version(s){
	  var id = $(s).parents("tr").children("td:eq(0)").children("input:eq(0)").val();
	  var company = $(s).parents("tr").children("td:eq(0)").children("input:eq(1)").val();
	  
	  if(company=="库存"){
         receive_update(id);
	  }else{
         send_update(id);
      }
   }    


  function second_send(send){
	  var id = $(send).parents("tr").children("td:eq(0)").children("input:eq(0)").val();
      $.ajax({
      	   type: "POST",
      	   url:"<?php echo  base_url();?>administrator/get_secondsend_data",
      	   data: "send_id="+id,
             dataType:'json', 
      	   success: function(msg){   
		    var st = '<table class="listing form" cellpadding="0" cellspacing="0" style="width:550px;margin-left:185px;"><input type="hidden" id="pre_count" />';
		      st+='<input type="hidden" id="pre_version" /><input type="hidden" id="current_company" /><input type="hidden" id="mod_id" /><input type="hidden" id="send_id" /><input type="hidden" id="category_id" /><input type="hidden" id="pre_company" /><input type="hidden" id="pre_codes" />';
		   	  st+='<tr><th  colspan="2"  align="center">资料二次分发</th></tr>';
		   	  st+='<tr><td style="width:130px;text-align:right;"><strong>型号：</strong></td><td style="text-align:left;"><span id="mod_id_notice"></span></td></tr>';
		   	  st+='<tr><td style="width:130px;text-align:right;"><strong>资料种类：</strong></td><td style="text-align:left;"><span id="category_id_notice"></span></td></tr>';
		   	  st+='<tr><td style="width:130px;text-align:right;"><strong>资料版本：</strong></td><td style="text-align:left;"><span id="current_id_notice">'+msg.current_version+'</span></td></tr>';
		   	  st+='<tr><td style="width:130px;text-align:right;"><strong>当前单位：</strong></td><td style="text-align:left;"><span>'+msg.current_company+'</span></td></tr>';
			  st+='<tr><td style="width:130px;text-align:right;"><strong>当前分发份数：</strong></td><td style="text-align:left;"><span>'+msg.count+'</span></td></tr>';
		      st+='<tr><td style="width:130px;text-align:right;"><strong>二次分发单位：</strong></td><td style="text-align:left;"><select name="next_company" id="next_company"></select></td></tr>';
		   	  st+='<tr class="bg"><td style="width:130px;text-align:right;"><strong>二次分发单据号：</strong></td><td style="text-align:left;"><input type="text" class="text" name="codes" id="codes" value="" /></td></tr>';
		   	  st+='<tr class="bg"><td style="width:130px;text-align:right;"><strong>二次分发人员：</strong></td><td style="text-align:left;"><input type="text" class="text" name="user_id" id="user_id" value="张永军" /></td></tr>';
			   	st+='<tr class="bg"><td style="width:130px;text-align:right;"><strong>二次分发时间：</strong></td><td style="text-align:left;"><input type="text" class="text" name="updatetime" id="updatetime" value="" /><span>1970.01.01</span></td></tr>';
		   	  st+='<tr class="bg"><td style="width:130px;text-align:right;"><strong>二次分发份数：</strong></td><td style="text-align:left;"><input type="text" class="text" name="count" onKeyUp=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) onafterpaste=this.value=this.value.match(/^[0-9]*[1-9][0-9]*$/)==null?"":this.value.match(/^[0-9]*[1-9][0-9]*$/) id="count" value="" /><span id="count_notice"></span></td></tr>';
		   	  st+='<tr class="bg"><td style="width:130px;text-align:right;"><strong>备注：</strong></td><td style="text-align:left;"><textarea name="des" cols="50" rows="5" id="des"></textarea></td></tr>';
		   	  st+='<tr><td colspan="2"><input type="button" value="提交" class="button" onclick="send_second_data()" id="submit"/><input type="button" value="返回" class="button" onclick="return_receive('+msg.category_id+')"/></td></tr></table>';   
		   	   $("#version_detail").html('');	   
		   	   $("#version_detail").html(st);   	          	  
        	   $("#mod_id_notice").html(msg.mod);
        	   $("#category_id_notice").html(msg.category);
        	   $("#next_company").html(msg.companys);
        	   $("#mod_id").val(msg.mod_id);
        	   $("#send_id").val(msg.send_id);
        	   $("#category_id").val(msg.category_id);
        	   $("#pre_company").val(msg.company_id);
        	   $("#pre_count").val(msg.count);
        	   $("#des").val(msg.des);
        	   $("#pre_codes").val(msg.codes);
        	   $("#pre_version").val(msg.pre_verison);  
        	   $("#current_company").val(msg.current_company);	       
      	   }
      	});
  }


  function send_second_data(){
       var pre_count = $("#pre_count").val();
       var count = $("#count").val();
       var pre_company = $("#pre_company").val();
       var next_company = $("#next_company").val();
       var mod_id = $("#mod_id").val();
       var mod_name = $("#mod_id_notice").html();
       var category_id = $("#category_id").val();
       var category_name = $("#category_id_notice").html();
       var version_name = $("#current_id_notice").html();
       var version_id = $("#pre_version").val();
       var codes = $("#codes").val();
       var pre_codes = $("#pre_codes").val();
       var user_id = $("#user_id").val();
       var des = $("#des").val();
       var send_id = $("#send_id").val();
       var updatetime = $("#updatetime").val();
       var current_company = $("#current_company").val();
       if(count==''){
          alert("二次分发份数不能空");
          return false;
        }
       if(parseInt(count)>parseInt(pre_count)){
           alert('二次分发份数不能大于原来份数');
           return false;
       }
       if(codes==""){
           alert("发放单据号不能空!");
           return false;
       }
       var str = "current_company="+current_company+"&updatetime="+updatetime+"&user="+user_id+"&pre_codes="+pre_codes+"&codes="+codes+"&pre_company="+pre_company+"&next_company="+next_company
       +"&mod_id="+mod_id+"&mod="+mod_name+"&category_id="+category_id+"&category="+category_name+"&des="+des+"&version_id="+version_id+
       "&version="+version_name+"&pre_count="+pre_count+"&count="+count+"&send_id="+send_id;
       $.ajax({
       	   type: "POST",
       	   url:"<?php echo  base_url();?>administrator/second_send",
       	   data: str, 
       	   success: function(msg){                    
                   if(msg=='1'){
                     alert("操作成功!");
                     $(".simplemodal-close").click();
                     $("#submit").attr("disabled",false);
                     window.location.reload();
                   }else{
                      alert(msg);
                      $("#submit").attr("disabled",false);
                     }
       	   }
       	});
     	
  }
</script>
